const VueLoaderPlugin = require('vue-loader/lib/plugin');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const path = require('path');
module.exports = {
  entry: './src/main.js',
  output: {
    filename: '[name].[hash:8].bundle.js',
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        use: ['vue-loader'],
      },
      {
        test: /\.js/,
        use: {
          loader: 'babel-loader',
          options: { presets: ['@vue/cli-plugin-babel/preset'] },
        },
        include: [path.resolve(__dirname, 'src')],
      },
      {
        enforce: 'pre',
        test: /\.(js|vue)$/,
        loader: 'eslint-loader',
        exclude: /node_modules/,
      },
      {
        test: /\.png$/,
        use: {
          loader: 'url-loader',
          options: {
            esModule: false,
            limit: 10 * 1024, // 10KB
          },
        },
      },
      {
        test: /\.less$/,
        use: ['vue-style-loader', 'css-loader', 'less-loader'],
      },
      {
        test: /\.css$/,
        use: ['vue-style-loader', 'css-loader'],
      },
    ],
  },
  plugins: [
    new VueLoaderPlugin(),
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      title: 'guolihang',
      template: './public/index.html',
      templateParameters: {
        BASE_URL: './',
      },
    }),
    // new webpack.DefinePlugin({
    //   BASE_URL: JSON.stringify('./'),
    // }),
  ],
};
